package org.vacoor.ticket.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
	
	public static String formatDate(Date date,String pattern) {
		return new SimpleDateFormat(pattern).format(date);
	}
	
	public static Date parseDate(String date,String[] pattern) throws ParseException {
		for(int i=0;i<pattern.length;i++) {
			try{
				return new SimpleDateFormat(pattern[i]).parse(date);
			}catch(ParseException e) {
				if( (i+1) ==pattern.length) {
					throw e;
				}
			}
		}
		return null;
	}
}
